﻿<controls:ChildWindow x:Class="AdminModule.Views.ViewAnswerLogDetails"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
           xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
           xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
           xmlns:usercontrols="clr-namespace:AdminModule.UserControls.Common"
           xmlns:converter="clr-namespace:AdminModule.Converters"
           xmlns:ansLog="clr-namespace:AdminModule.AnswerLog"
           Loaded="ChildWindow_Loaded"
           Width="850" Height="600" 
           Title="">
    
    <controls:ChildWindow.Resources>
        <converter:AnswerLogImagesConverter x:Key="answerLogImagesConverter" />
        <converter:AnswerLogHintsConverter x:Key="answerLogHintsConverter"></converter:AnswerLogHintsConverter>
        <converter:DateTimeConverter x:Key="dateTimeConverter" />
        <ansLog:BoolToVisibilityConverter x:Key="vc"/>
        <converter:RoundConverter x:Key="roundConverter"></converter:RoundConverter>
        <ansLog:MarginConverter x:Key="mc"/>
        
        <ControlTemplate TargetType="ToggleButton" x:Key="btnTemplate">
            <Grid x:Name="Root" Background="Transparent">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <ColorAnimation Duration="0" Storyboard.TargetName="UncheckedVisual" Storyboard.TargetProperty="(Path.Stroke).Color" To="#FF1BBBFA"/>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Disabled">
                            <Storyboard>
                                <DoubleAnimation Duration="0" Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To=".7"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                    <VisualStateGroup x:Name="CheckStates">
                        <VisualState x:Name="Unchecked"/>
                        <VisualState x:Name="Checked">
                            <Storyboard>
                                <DoubleAnimation Duration="0" Storyboard.TargetName="UncheckedVisual" Storyboard.TargetProperty="Opacity" To="0"/>
                                <DoubleAnimation Duration="0" Storyboard.TargetName="CheckedVisual" Storyboard.TargetProperty="Opacity" To="1"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Grid HorizontalAlignment="Right" Margin="2 2 5 2">
                    <Path x:Name="UncheckedVisual" Fill="#FFFFFFFF" Stroke="#FF989898" StrokeLineJoin="Miter" StrokeThickness="1" Height="9" HorizontalAlignment="Right" VerticalAlignment="Center" Width="6" Data="M 0,0 L 0,9 L 5,4.5 Z"/>
                    <Path x:Name="CheckedVisual" Fill="#FF262626" StrokeLineJoin="Miter" Height="6" HorizontalAlignment="Center" VerticalAlignment="Center" Width="6" Opacity="0" Data="M 6,0 L 6,6 L 0,6 Z"/>
                </Grid>
            </Grid>
        </ControlTemplate>
    </controls:ChildWindow.Resources>
    
    <Grid x:Name="LayoutRoot" Margin="2">
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Button IsEnabled="False" Grid.Row="0" HorizontalAlignment="Left" Height="24" VerticalAlignment="Top" Margin="0,0,0,0" ToolTipService.ToolTip="Удалить" x:Name="deleteButton" Click="deleteButton_Click">
            <StackPanel Orientation="Horizontal">
                <Image Source="/AdminModule;Component/Images/Delete.png" Width="18" Height="18"></Image>
                <TextBlock Margin="5,0,5,0" VerticalAlignment="Center" Text="Удалить отмеченные"></TextBlock>
            </StackPanel>
        </Button>

        <data:DataGrid Margin="0,29,0,0" Grid.Row="0" x:Name="dataGrid" IsReadOnly="True" AutoGenerateColumns="False" SelectionMode="Single">
            <data:DataGrid.Columns>
                <data:DataGridTemplateColumn>
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox ToolTipService.ToolTip="Удалить" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center" Tag="{Binding}"></CheckBox>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="{Binding Level, Converter={StaticResource mc}}">
                                <ToggleButton x:Name="ExpanderButton" IsChecked="{Binding IsExpanded, Mode=TwoWay}" 
                                  Visibility="{Binding HasChildren, Converter={StaticResource vc}}" 
                                  VerticalAlignment="Center" IsTabStop="False" TabNavigation="Once" Margin="2" Template="{StaticResource btnTemplate}"/>
                                <TextBlock Text="{Binding Item.DateTime}" VerticalAlignment="Center"/>
                            </StackPanel>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Margin="5,0,5,0" Source="{Binding Path=Item.Operation, Converter={StaticResource answerLogImagesConverter}}" ToolTipService.ToolTip="{Binding Path=Item.Operation, Converter={StaticResource answerLogHintsConverter}}"></Image>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="Дата и время">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock VerticalAlignment="Center" ToolTipService.ToolTip="число.месяц.год, часы:минуты">
                                    <TextBlock.Text>
                                        <Binding Path="Item.CurrentTime" Converter="{StaticResource dateTimeConverter}" ConverterParameter="0:dd.MM.yy, HH:mm" />
                                    </TextBlock.Text>
                            </TextBlock>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="Пользователь">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Item.UserName}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="Показатель / градации">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel VerticalAlignment="Center" Orientation="Vertical">
                                <TextBlock Width="390" TextWrapping="Wrap" FontWeight="Bold" Text="{Binding Path=Item.Characteristic.Name}" />
                                <ListBox BorderThickness="0" ItemsSource="{Binding Path=Item.Gradations}" Background="Transparent" BorderBrush="Transparent">
                                    <ListBox.ItemTemplate>
                                        <DataTemplate>
                                            <StackPanel Orientation="Horizontal">
                                                <CheckBox ToolTipService.ToolTip="Удалить" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked" Tag="{Binding}"></CheckBox>
                                                <TextBlock Width="390" TextWrapping="Wrap" Text="{Binding}"></TextBlock>
                                            </StackPanel>
                                        </DataTemplate>
                                    </ListBox.ItemTemplate>
                                </ListBox>
                            </StackPanel>
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="Сотрудник">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Item.Respondent.Person.ShortFIO}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="Отдел">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock ToolTipService.ToolTip="{Binding Path=Item.Respondent.Department.Name}" Text="{Binding Path=Item.Respondent.Department.Abbriviation}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>

                <data:DataGridTemplateColumn Header="Значение">
                    <data:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Path=Item.Volume, Converter={StaticResource roundConverter}, ConverterParameter='2'}" VerticalAlignment="Center" HorizontalAlignment="Center" />
                        </DataTemplate>
                    </data:DataGridTemplateColumn.CellTemplate>
                </data:DataGridTemplateColumn>
            </data:DataGrid.Columns>
        </data:DataGrid>

        <usercontrols:ProgressBar IsVisibility="Collapsed" VerticalAlignment="Center" HorizontalAlignment="Center" x:Name="progressBar"></usercontrols:ProgressBar>

        <Button x:Name="CancelButton" Content="Закрыть" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
        <!--<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />-->
    </Grid>
</controls:ChildWindow>